home *** CD-ROM | disk | FTP | other *** search
- property pCompassSprite, pArrowsSprite, pTextSprite, pTextField, pCurVal, pCallBackObj, pRefcon, pRange, pMin, pMax, pCenterPoint, pActive
-
- on new me, propList
- set pCompassSprite to getaProp(propList, #lineSprite)
- set pArrowsSprite to getaProp(propList, #arrowsSprite)
- set pTextSprite to getaProp(propList, #textSprite)
- set pTextField to getaProp(propList, #textField)
- set pCenterPoint to getaProp(propList, #center)
- set pMin to -720
- set pMax to 720
- set pCurVal to getaProp(propList, #cur)
- set pRange to pMax - pMin
- set pActive to getaProp(propList, #active)
- set pCallBackObj to getaProp(propList, #callback)
- set pRefcon to getaProp(propList, #ref)
- SetVal(me, pCurVal)
- SetEnabled(me, pActive)
- return me
- end
-
- on wait me, waitTime
- set t to the ticks
- repeat while the ticks < (t + waitTime)
- end repeat
- end
-
- on click me
- if not pActive then
- exit
- end if
- repeat while the stillDown
- set x to the mouseH - the locH of sprite the clickOn
- set y to the mouseV - the locV of sprite the clickOn
- if x = 0 then
- set x to -0.0001
- end if
- set a to atan(float(y) / x) + (0.5 * PI)
- if x < 1 then
- set a to a + PI
- end if
- set a to integer(a / (2 * PI) * 360)
- if a > 180 then
- set a to a - 360
- end if
- SetVal(me, a)
- if objectp(pCallBackObj) then
- compassChange(pCallBackObj, pRefcon, a)
- end if
- updateStage()
- end repeat
- if objectp(pCallBackObj) then
- EndChange(pCallBackObj)
- end if
- end
-
- on Arrows me
- if not pActive then
- exit
- end if
- set h1 to the locH of the clickLoc
- set h2 to the locH of sprite the clickOn
- if h1 < h2 then
- set side to "left"
- set d to -1
- else
- set side to "right"
- set d to 1
- end if
- set the member of sprite pArrowsSprite to member ("horizArrows" && side)
- set newVal to max(min(pCurVal + d, pMax), pMin)
- if objectp(pCallBackObj) then
- compassChange(pCallBackObj, pRefcon, newVal)
- end if
- updateStage()
- wait(me, 5)
- repeat while the stillDown
- if rollOver(pArrowsSprite) then
- set the member of sprite pArrowsSprite to member ("horizArrows" && side)
- set pCurVal to max(min(pCurVal + d, pMax), pMin)
- else
- set the member of sprite pArrowsSprite to member "horizArrows"
- end if
- SetVal(me, pCurVal)
- if objectp(pCallBackObj) then
- compassChange(pCallBackObj, pRefcon, newVal)
- end if
- wait(me, 5)
- end repeat
- set the member of sprite pArrowsSprite to member "horizArrows"
- if objectp(pCallBackObj) then
- EndChange(pCallBackObj)
- end if
- end
-
- on TextOut me
- if the platform contains "Mac" then
- set degreeSymbol to numToChar(161)
- else
- set degreeSymbol to numToChar(186)
- end if
- if voidp(pCurVal) then
- put " " into field pTextField
- else
- put string(integer(pCurVal)) & degreeSymbol into field pTextField
- end if
- end
-
- on SetVal me, newVal
- puppetSprite(pThumbSprite, 1)
- set pCurVal to newVal
- drawLine(me)
- TextOut(me)
- end
-
- on drawLine me
- puppetSprite(pCompassSprite, 1)
- set a to (float(pCurVal) / 360 * 2 * PI) - (0.5 * PI)
- set x to integer(cos(a) * 14)
- set y to integer(sin(a) * 14)
- if (x = 1) or (x = 0) then
- set x to 2
- else
- if x = -1 then
- set x to -2
- else
- if (y = 1) or (y = 0) then
- set y to 2
- else
- if y = -1 then
- set y to -2
- end if
- end if
- end if
- end if
- set r to rect(pCenterPoint, pCenterPoint + point(x, y))
- if ((x < 0) and (y > 0)) or ((x > 0) and (y < 0)) then
- set the castNum of sprite pCompassSprite to the number of member "line2"
- else
- set the castNum of sprite pCompassSprite to the number of member "line1"
- end if
- set the rect of sprite pCompassSprite to r
- end
-
- on SetEnabled me, enabled
- set pActive to enabled
- enableInterfaceElement(pCompassSprite, enabled)
- enableInterfaceElement(pArrowsSprite, enabled)
- enableInterfaceElement(pTextSprite, enabled)
- end
-
- on Release me
- end
-